﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Azure.TableQuery.Core;
using Microsoft.WindowsAzure.StorageClient;

namespace Azure.TableQuery.Tests
{
    
    [TestClass]
    public class EntityTextBuilderFixture : BaseTest
    {
        GenericEntity entity;
        public EntityTextBuilderFixture()
            : base()
        {
            var tableClient = new CloudTableClient(@"http://ipv4.fiddler:10002/devstoreaccount1",
                account.Credentials);

            var context = new GenericTableContext(tableClient.BaseUri.ToString(), account.Credentials);
            entity = context.GetFirstOrDefault("TestEntity");
        }

        [TestMethod]
        public void BuildEntity()
        {
            EntityQueryBuilder builder = new EntityQueryBuilder();
            
            builder.AddQuery(entity, "from te in TestEntityTable where te.Name == \"something\" select te");
            
            var text = builder.ToString();
            Assert.IsTrue(text.IndexOf("class TestEntity") > 0);
            Assert.IsTrue(text.IndexOf("class TestEntityContext") > 0);
            Assert.IsTrue(text.IndexOf("public System.String Name { get; set; }") > 0);
        }
    }
}
